package com.creditcmsplt;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * spring boot入口 也可以是@SpringBootApplication 低版本springboot不支持该写法
 * 
 * @author 雷阳军
 * @Configuration
 * @EnableAutoConfiguration
 * @ComponentScan
 *
 */
@SpringBootApplication
@EnableSwagger2
@MapperScan("com.creditcmsplt.mapper")
public class App {
	
	public static void main(String[] args) {
		SpringApplication.run(App.class, args);
	}

	@Bean
	@Profile("linuxdev")
    public Docket createLinuxdevRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo()).enable(true)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.creditcmsplt.controller")) //扫描文档注解的包路径
                .paths(PathSelectors.any())
                //.paths(Predicates.or(PathSelectors.regex("/credit/convertPdf")))
                //.paths(PathSelectors.ant("/credit/convertPdf"))
                .build();
    }
	
	@Bean
	@Profile("localdev")
    public Docket createLocaldevRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo()).enable(true)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.creditcmsplt.controller")) //扫描文档注解的包路径
                .paths(PathSelectors.any())
                //.paths(Predicates.or(PathSelectors.regex("/credit/convertPdf")))
                //.paths(PathSelectors.ant("/credit/convertPdf"))
                .build();
    }
	
	@Bean
	@Profile("pro")
    public Docket createProRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo()).enable(false)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.creditcmsplt.controller")) //扫描文档注解的包路径
                .paths(PathSelectors.any())
                //.paths(Predicates.or(PathSelectors.regex("/credit/convertPdf")))
                .paths(PathSelectors.ant("/credit/convertPdf"))
                .build();
    }

	/** 指定了页面显示的信息，标题、描述 */
	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("触云--金融数据部统一开发平台在线接口文档（可在前段通过js调用，已经做了跨域处理）").contact(new Contact("雷阳军", "https://wiair.com", "leiyangjun@wiair.com"))
				.description("\r\n&nbsp;&nbsp;&nbsp;包含现场查询、pdf转换、非现场查询等接口api描述,如有疑问，请联系金融数据部IT工程师。  \r\n\r\n-----金融数据部").version("v1.0").build();
	}

}
